#include "Scene.hpp"

Scene::Scene() {
    this->actionableElements = new vector<ActionableElement*>();
    this->boxElements = new vector<BoxElement*>();
    this->elements = new vector<Element*>();
    this->message = NULL;
    this->moveablePlatformElements = new vector<MoveablePlatformElement*>();
    this->spotlights = new vector<SpotlightElement*>();
    this->roomDepth = 7.0f;

    b2Vec2 gravity(0.0f, -9.8f);
    this->world = new b2World(gravity);
}

Scene::~Scene() {
    delete this->actionableElements;
    delete this->boxElements;
    delete this->elements;
    delete this->moveablePlatformElements;
    delete this->spotlights;
    delete this->world;
}

BoxElement* Scene::createBox(float x, float y) {
    BoxElement* box = new BoxElement(x, y, this->world);
    this->elements->push_back(box);
    this->boxElements->push_back(box);
    return box;
}

DoorElement* Scene::createDoor(float x, float y, float wallDirection) {
    DoorElement* door = new DoorElement(x, y, wallDirection, this->world);
    this->elements->push_back(door);
    this->actionableElements->push_back(door);
    return door;
}

ExitElement* Scene::createExit(float x, float y) {
    ExitElement* exit = new ExitElement(x, y, this->world);
    this->elements->push_back(exit);
    return exit;
}

FlashElement* Scene::createFlash(float x, float y, float angle, const b2Vec2 impulse) {
    FlashElement* flash = new FlashElement(x, y, angle, impulse, this->world);
    this->elements->push_back(flash);
    return flash;
}

HeroElement* Scene::createHero(float x, float y) {
    HeroElement* hero = new HeroElement(x, y, this->world);
    this->elements->push_back(hero);
    return hero;
}

MoveablePlatformElement* Scene::createMoveablePlatformElement(const b2Vec2* vertices, int numberOfVertices, const b2Vec2 start, const b2Vec2 end, float velocity) {
    MoveablePlatformElement* moveablePlatform = new MoveablePlatformElement(vertices, numberOfVertices, start, end, velocity, this->room, this->world);
    this->elements->push_back(moveablePlatform);
    this->actionableElements->push_back(moveablePlatform);
    this->moveablePlatformElements->push_back(moveablePlatform);
    return moveablePlatform;
}

PlatformElement* Scene::createPlatform(const b2Vec2* vertices, int numberOfVertices) {
    PlatformElement* platform = new PlatformElement(vertices, numberOfVertices, this->world);
    this->elements->push_back(platform);
    return platform;
}

RoomElement* Scene::createRoom(int roomNumber, const b2Vec2* vertices, int numberOfVertices) {
    this->room = new RoomElement(roomNumber, vertices, numberOfVertices, this->world);
    this->elements->push_back(this->room);
    return this->room;
}

SpotlightElement* Scene::createSpotlight(float x, float y, float angle, float arc, float length, LightElement::Type lightType) {
    SpotlightElement* spotlight = new SpotlightElement(x, y, angle, arc, length, lightType, this->world);
    this->elements->push_back(spotlight);
    this->actionableElements->push_back(spotlight);
    this->spotlights->push_back(spotlight);
    return spotlight;
}

SwitchElement* Scene::createSwitch(float x, float y, float angle, ActionableElement* actionableElement) {
    SwitchElement* switchElement = new SwitchElement(x, y, angle, actionableElement, this->world);
    this->elements->push_back(switchElement);
    return switchElement;
}

void Scene::setMessage(const string &message) {
    this->message = new string(message);
}
